;$(function(){
	
   replayComment();
   
   $("#articleCommentContent").on("blur",function(){
	   if($(this).val() == "")
	   {
		   $("#parentCommentHashId").val("");
		   $("#parentUserId").val("");
		   $("#articleCommentContent").attr("placeholder","请输入评论");
		   $("#articleCommentParentUserName").val("");
		   $("#articleCommentContent").val("");
	   }
   });
    
    var commentSubmitFlag = true;
    $(document).off("click.dialog_detail").on("click.dialog_detail","#submitButton",function(e)
	{
	 	var isResult=Ace.chkIsLogin(this,e);
       	if(isResult==false){
       	  return false;
     	}
       	
       	var content = $("#articleCommentContent").val().trim();
    	var hashId = $("#articleHashId").val();
    	if (content.getStringLength() > 400) 
    	{
    		jAlert("评论内容太长！");
    		return false;
    	}
    	else if(content.getStringLength() < 2 || content == '请输入评论')
    	{
    		jAlert("请输入评论内容！");
    		return false;
    	}
       	
       	var userName = $(this).attr("username");
       	
       	if(commentSubmitFlag)
       	{
       		commentSubmitFlag = false;
       		Ace.denyButton(this);
       		$.ajax({
       			url:"/dialog/addcomment?_"+Date.parse(new Date()),
       			type: "POST",
       			data: {
       				articleCommentContent:$("#articleCommentContent").val(),
       				articleHashId:$("#articleHashId").val(),
       				parentCommentHashId:$("#parentCommentHashId").val(),
       				parentUserId:$("#parentUserId").val()
       			},
       			success:function(data){
       				if(data!=null)
       				{
       					$("#commentsDiv").empty().append(data);
       					$("#parentCommentHashId").val("");
       					$("#parentUserId").val("");
       					$("#articleCommentParentUserName").val("");
       					$("#articleCommentContent").attr("placeholder","请输入评论");
       					$("#articleCommentContent").val("");
       					commentSubmitFlag = true;
       					replayComment();
	       				 var colsLH=$("#J_dialog_detail .J_cols_l").outerHeight();
	       				 var $_rCols=$("#J_dialog_detail .J_cols_r");
	       				 	 $_rCols.removeAttr("style");
	                     var colsRH=$_rCols.outerHeight();
	                     //右侧大于左边的，设置scroll
	                     if(colsRH>colsLH){
	                         var $_ul=$_rCols.find(".secord-media-list");
	                         $_ul.css({
	                            "overflow-y":"scroll",
	                             "height": colsLH-250
	                         });
	                         $_rCols.css("height",colsLH+30);
	                     }else{
	                    	 $_rCols.css("height",colsLH); 
	                     }
       				}
       			}
       		});
       	}
	});
});

var complaintFlag = true;

function addComplaint(obj)
{
	var url=$(obj).attr("data-url");
	var $_self=$("#complaint_"+$(obj).attr("objId"));
	complaintFlag = false;
	
	if($('input:radio[name=reasonType]:checked').size() < 1)
	{
		jAlert("请选择纠错类型！");
		return false;
	}
	var reasonType = $('input:radio[name=reasonType]:checked').val();
	var reasonContent = $('input:radio[name=reasonType]:checked').attr("content");
	if(reasonType == "7")
	{
		reasonContent = $('#reasonContent').val();
		if(reasonContent.getStringLength() < 2)
		{
			jAlert("请输入纠错美容！");
			return false;
		}	
		else if(reasonContent.getStringLength() > 200)
		{
			jAlert("输入纠错美容过长！");
			return false;
		}
	}
	
	$.ajax({
	  url: url,
	  type: "POST",
	  dataType: 'json',
	  data: "complaintReasonType="+reasonType+"&complaintReason="+reasonContent,
	  success: function(data){
			if(data.success){
				if(data.isComplaint)
				{
					jAlert("纠错内容已提交！",function(){$('#modal_complaint_dialog').modal('hide');});
				}
				else
				{
					jAlert("已经纠错过了，正在处理！",function(){$('#modal_complaint_dialog').modal('hide');});
				}
				$_self.attr("href", "javascript:jAlert('已经纠错过了，正在处理！');");
				$_self.removeAttr("data-target");
				$_self.removeAttr("data-toggle");
				$_self.removeAttr("data-destory-inner");
				complaintFlag = true;
			}	
	  }
	});
}

function replayComment(){
	$(".a-feedback").off("click").on("click",function(e){
	    var isResult=Ace.chkIsLogin(this,e);
      	if(isResult==false){
      	  return false;
    	}
	   $("#parentCommentHashId").val($(this).attr("parentId"));
	   $("#parentUserId").val($(this).attr("userId"));
	   $("#articleCommentParentUserName").val($(this).attr("username"));
	   $("#articleCommentContent").attr("placeholder","回复："+$(this).attr("userName"));
	   $("#articleCommentContent").focus();
   });
}